//------------Sonic CD BGEffects Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 16: TYPE_BGEFFECTS


sub ObjectDraw
	Object.AnimationTimer++
	if Object.AnimationTimer>15
		Object.AnimationTimer=0
		Object.Value7++
		Object.Value7%=3
		SetActivePalette(Object.Value7,0,Screen.YSize)
	endif
	if Object.Value6==0
		if Object[4].Value1<20
			PlayMusic(2)
			Object.Value6=1
		endif
	else
		if Object[4].Value1>=20
			if Object.Value6==1
				PlayMusic(0)
			endif
			Object.Value6=0
		endif
	endif
	if Object[30].Type==TypeName[StageFinish]
		if Object[30].PropertyValue==0
			SetMusicTrack("SS2FinishBad.ogg",1,409948)
		endif
	endif
	TempValue1=Object.Value2
	TempValue2=TileLayer[0].Angle
	if TempValue1<TempValue2
		TempValue3=TempValue2
		TempValue3-=TempValue1
		if TempValue3>256
			TempValue1+=512
		endif
	else
		TempValue3=TempValue1
		TempValue3-=TempValue2
		if TempValue3>256
			TempValue2+=512
		endif
	endif
	TempValue0=TempValue1
	TempValue0-=TempValue2
	Object.Value2=TileLayer[0].Angle
	TempValue0*=131072
	HParallax[0].ScrollPos+=TempValue0
endsub


sub ObjectStartup
	SetMusicTrack("SS2.ogg",0,318788)
	SetMusicTrack("SS2FinishGood.ogg",1,267100)
	SetMusicTrack("SS2Pinch.ogg",2,0)
	Stage.XBoundary1=6291456
	Stage.XBoundary2=127926272
	Stage.YBoundary1=6291456
	Stage.YBoundary2=127926272
#platform: HW_Rendering
	LoadSpriteSheet("Special/SSMap2.gif")
#endplatform
	ArrayPos0=32
	while ArrayPos0<1056
		if Object[ArrayPos0].Type==TypeName[BGEffects]
			Object[ArrayPos0].Priority=1
			Object[ArrayPos0].DrawOrder=0
			Object[ArrayPos0].Value2=368
			Object[ArrayPos0].Value6=2
		else
			Object[ArrayPos0].XPos<<=1
			Object[ArrayPos0].YPos<<=1
		endif
		ArrayPos0++
	loop
	RotatePalette(212,214,1)
	RotatePalette(215,217,1)
	RotatePalette(218,220,1)
	RotatePalette(221,223,1)
	CopyPalette(0,1)
	RotatePalette(212,214,1)
	RotatePalette(215,217,1)
	RotatePalette(218,220,1)
	RotatePalette(221,223,1)
	CopyPalette(0,2)
	RotatePalette(212,214,1)
	RotatePalette(215,217,1)
	RotatePalette(218,220,1)
	RotatePalette(221,223,1)
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
